Skip to content

feat(gax): enter inScope() during CompositeTracer completion callbacks - #15034

Draft
jinseopkim0 wants to merge 8 commits into
mainfrom
feat-composite-tracer-callback-scope
Draft

jinseopkim0 wants to merge 8 commits into
mainfrom
feat-composite-tracer-callback-scope

Conversation

@jinseopkim0

Copy link
Copy Markdown
Contributor

Updates CompositeTracer to wrap attempt and operation completion/failure callbacks in try (Scope ignored = inScope()) (with a null guard for unstubbed test mocks) so sibling and nested tracers execute with the active trace scope on the callback thread.

b/499388983

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CompositeTracer to wrap its lifecycle and attempt completion methods within the tracer's scope using a try-with-resources block, and adds a null check to ignore null child scopes in inScope(). Corresponding unit tests have been added to verify these scoping behaviors, including nested composite tracers and cross-thread scoping. I have no additional feedback to provide as no review comments were submitted.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CompositeTracer to execute operation and attempt lifecycle methods within the active scope and safely handle null scopes returned by unstubbed mocks. It also adds unit tests to verify scope management and cross-thread scoping. Feedback on these changes suggests catching Throwable instead of RuntimeException when establishing child scopes to prevent potential thread-local scope leaks if an Error occurs during scope creation.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances CompositeTracer by wrapping operation and attempt methods in try-with-resources blocks to manage scopes correctly. It also improves robustness by handling Error alongside RuntimeException during scope creation and closing, ignoring null child scopes, and ensuring scope closure is idempotent. The review feedback suggests optimizing the inScope implementation by replacing AtomicBoolean with a local class to reduce object allocation and memory barrier overhead, which would also make the AtomicBoolean import redundant.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CompositeTracer to handle null scopes returned by child tracers, catch and propagate Errors alongside RuntimeExceptions, and wrap child tracer callbacks in their corresponding scopes using try-with-resources. It also replaces the anonymous Scope implementation with a CompositeScope class to prevent double-closing. Comprehensive unit tests are added to verify these behaviors, including cross-thread scoping scenarios. The reviewer suggested optimizing inScope() to avoid allocations when there are zero or one child tracers.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CompositeTracer to optimize scope handling (including fast paths for empty or single-child lists), catch and handle Error alongside RuntimeException, and wrap operation and attempt methods in try-with-resources blocks to manage scopes properly. Comprehensive unit tests are added to cover these scenarios. The review feedback highlights a potential concurrency issue in CompositeScope.close(), where the check-and-set operation on the volatile closed flag is not atomic, and suggests using a ReentrantLock to ensure thread-safe idempotency.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances CompositeTracer to manage scopes more robustly, introducing fast paths for empty or single-child tracers, catching Error alongside RuntimeException during scope closure, and wrapping completion methods in try-with-resources blocks to ensure proper scoping. It also introduces a thread-safe CompositeScope to prevent duplicate closures. The reviewer suggests replacing the ReentrantLock in CompositeScope with a more lightweight and idiomatic AtomicBoolean to track the closed state, which reduces boilerplate and avoids lock acquisition overhead.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances CompositeTracer to safely handle null scopes from unstubbed mocks, catch Errors alongside RuntimeExceptions for proper cleanup, and wrap tracer operations in inScope() blocks to ensure thread-bound execution. Comprehensive unit tests are also added to verify these behaviors. The reviewer suggests further optimizing the inScope() method by avoiding anonymous Scope wrapper allocations when childScopes is empty or has a single active scope, while maintaining exception safety.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates CompositeTracer to properly manage scope lifecycle and handle potential null scopes or Error throwables. Specifically, it introduces fast paths for empty or single-child tracers, ignores null child scopes, catches and propagates Error alongside RuntimeException to ensure proper cleanup, and wraps all operation and attempt completion methods in a try-with-resources block using inScope(). Additionally, comprehensive unit tests have been added to verify these new behaviors, including edge cases for null scopes, errors, and cross-thread scoping. There are no review comments, and we have no further feedback to provide.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant